package br.senai.sc.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Filter implements javax.servlet.Filter {

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse res = (HttpServletResponse) response;
		
		Object logged = req.getSession().getAttribute("isLogged");
		String url = req.getRequestURL().toString();

		if (logged == null && !url.contains("index.jsp")) {
			
			res.sendRedirect("http://localhost:8080/Avaliacao02/index.jsp");
			
			return;
		}

		chain.doFilter(request, response);
		
	
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {

	}

}
